package com.zyark.web.controller;

import com.zyark.domain.DemoManage;
import com.zyark.model.ServerResponseModel;
import com.zyark.service.DemoManageService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;

/**
 * Created by ron on 17-8-31.
 */
@Controller
@RequestMapping(value = "demo")
public class DemosManageController {

    @Resource
    DemoManageService demoManageService;

    @RequestMapping(value = "list",method = RequestMethod.GET)
    @ResponseBody
    public ServerResponseModel<DemoManage> getList(@RequestParam(value = "pageNumber",required = false)Integer pageNumber,
                                                   @RequestParam(value = "pageSize",required = false)Integer pageSize){
        if (pageNumber == null){
            pageNumber = 1;
        }
        if (pageSize == null){
            pageSize = 10;
        }
        return demoManageService.selectPageV2(pageNumber,pageSize);
    }

    @RequestMapping(method = RequestMethod.POST)
    @ResponseBody
    public Object addDemo(@RequestBody DemoManage demoManage){
          demoManage.setCreateTime(new Date());
          return demoManageService.saveSelective(demoManage);
    }

    @RequestMapping(value = "{id}",method = RequestMethod.POST)
    @ResponseBody
    public Object updateDemo(@RequestBody DemoManage demoManage){
        return demoManageService.updateSelective(demoManage);
    }

    @RequestMapping(value = "{id}",method = RequestMethod.DELETE)
    @ResponseBody
    public Object deleteOne(@PathVariable Integer id){
        return  demoManageService.delete(new DemoManage(id));
    }
}
